package com.xxl.job.executor.service.jobhandler;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.executor.crawler.job.AllSpecialProduct;
import com.xxl.job.executor.crawler.util.JedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;

/**
 * 描述:
 *
 * @author Pfly
 * @create 2019-01-03 11:10
 */
@JobHandler(value = "specialHandler")
@Component
public class SpecialJobHandler extends IJobHandler {
    @Autowired
    AllSpecialProduct allSpecialProduct;


    //此方法需要递归

    @Override
    public ReturnT<String> execute(String param) {
        Jedis jedis = JedisUtil.getJedis();
        XxlJobLogger.log("启动爬虫！");


        allSpecialProduct.start_crawler_sepcial();
        XxlJobLogger.log("爬虫结束！");

        if (jedis.lrange("sepcialUrl", 0, 1).size() == 0) {
            return SUCCESS;
        } else if(Integer.valueOf(param) == 0) {
            return SUCCESS;
        }
        return execute(String.valueOf(Integer.valueOf(param)-1));
       // return SUCCESS;
    }
}
